package com.springboot.demo.core.exception;

import com.springboot.demo.module.domain.BaseResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

/**
 * 异常处理
 *
 * @author Francis
 * @version 1.0
 * @date 2019-07-05 14:48
 */
@Slf4j
@ControllerAdvice
public class MyExceptionHandler {

    @ResponseBody
    @ExceptionHandler({CosyException.class})
    public Map<String, Object> handleBaseException(final CosyException exception) {
        log.error("发生了自定义异常：", exception);
        return BaseResult.ajaxReturn(exception.getCode(), exception.getMsg(), null);
    }
}
